package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/6/21 10:29
 * @apiNote
 */

public class LCP61TemperatureTrend {

    public int temperatureTrend(int[] temperatureA, int[] temperatureB) {
        int m = temperatureA.length;
        int count = 0;
        int ans = 0;
        int[] arrA = new int[m - 1];
        int[] arrB = new int[m - 1];
        for (int i = 1; i < m; i++) {
            arrA[i - 1] = getTrend(temperatureA[i],temperatureA[i-1]);
            arrB[i - 1] = getTrend(temperatureB[i],temperatureB[i-1]);
            if(arrA[i-1] == arrB[i-1]){
                count++;
                ans = Math.max(ans,count);
            }else{
                count = 0;
            }
        }
        return ans;
    }

    private static int getTrend(int x,int y){
        int temp = 0;
        if(x > y){
            temp = 1;
        }else if (x < y){
            temp = -1;
        }
        return temp;
    }
}
